package com.neutech.controller;

import com.mybatisflex.core.paginate.Page;
import com.neutech.vo.ResultJson;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import jakarta.annotation.Resource;
import com.neutech.entity.HomeWorkCommit;
import com.neutech.service.HomeWorkCommitService;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * 作业提交表 控制层。
 *
 * @author Administrator
 * @since 2025-06-19
 */
@RestController
@Tag(name = "作业提交表接口")
@RequestMapping("/homeWorkCommit")
public class HomeWorkCommitController {

    @Resource
    private HomeWorkCommitService homeWorkCommitService;

    /**
     * 添加作业提交表。
     *
     * @param homeWorkCommit 作业提交表
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("save")
    @Operation(summary = "保存作业提交表", description="保存作业提交表")
    public ResultJson<Boolean> save(HomeWorkCommit homeWorkCommit) {
        return ResultJson.success(homeWorkCommitService.save(homeWorkCommit));
    }

    /**
     * 根据主键删除作业提交表。
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @PostMapping("remove/{id}")
    @Operation(summary = "根据主键作业提交表", description="根据主键作业提交表")
    public ResultJson<Boolean> remove(@PathVariable Integer id) {
        return ResultJson.success(homeWorkCommitService.removeById(id));
    }

    /**
     * 根据主键更新作业提交表。
     *
     * @param homeWorkCommit 作业提交表
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PostMapping("update")
    @Operation(summary = "根据主键更新作业提交表", description="根据主键更新作业提交表")
    public ResultJson<Boolean> update(HomeWorkCommit homeWorkCommit) {
        return ResultJson.success(homeWorkCommitService.updateById(homeWorkCommit));
    }

    /**
     * 查询所有作业提交表。
     *
     * @return 所有数据
     */
    @GetMapping("list")
    @Operation(summary = "查询所有作业提交表", description="查询所有作业提交表")
    public ResultJson<List<HomeWorkCommit>> list() {
        return ResultJson.success(homeWorkCommitService.list());
    }

    /**
     * 根据作业提交表主键获取详细信息。
     *
     * @param id 作业提交表主键
     * @return 作业提交表详情
     */
    @GetMapping("getInfo/{id}")
    @Operation(summary = "根据主键获取作业提交表", description="根据主键获取作业提交表")
    public ResultJson<HomeWorkCommit> getInfo(Integer id) {
        return ResultJson.success(homeWorkCommitService.getById(id));
    }

    /**
     * 分页查询作业提交表。
     *
     * @param page 分页对象
     * @return 分页对象
     */
    @GetMapping("page")
    @Operation(summary = "分页查询作业提交表", description="分页查询作业提交表")
    public ResultJson<Page<HomeWorkCommit>> page(@Parameter(description="分页信息")Page<HomeWorkCommit> page) {
        return ResultJson.success(homeWorkCommitService.page(page));
    }
    @PostMapping("upload")
    @Operation(summary = "文件上传", description="文件上传")
    public ResultJson<Boolean> upload(MultipartFile file, HomeWorkCommit homeWorkCommit) throws Exception {
        return ResultJson.success(homeWorkCommitService.add(file, homeWorkCommit), "上传成功");
    }
    @PostMapping("read")
    ResultJson<Boolean> read(Integer id) throws IOException {
        return ResultJson.success(homeWorkCommitService.read(id), "批阅成功");
    }
}
